/**
 * 
 */
package com.qolome.config;

import java.util.ArrayList;
import java.util.List;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.cors.CorsConfiguration;
import org.springframework.web.cors.UrlBasedCorsConfigurationSource;
import org.springframework.web.filter.CorsFilter;

/**
 * @Description: 跨域配置
 * @author 姜锋
 * @date 2020年1月25日 下午4:57:22
 * @version V1.0
 */
@Configuration
public class CorsConfig {
	@Bean
	public CorsFilter corsFilter() {
		UrlBasedCorsConfigurationSource basedCorsConfigurationSource = new UrlBasedCorsConfigurationSource();
		CorsConfiguration corsConfiguration = new CorsConfiguration();
		// 支持Cookie跨域
		corsConfiguration.setAllowCredentials(true);
		// 支持原始域跨域
		List<String> allowedOrigins = new ArrayList<>();
		allowedOrigins.add("*.qolome.com");
		corsConfiguration.setAllowedOrigins(allowedOrigins);
		// 支持消息头跨域
		List<String> allowedHeaders = new ArrayList<>();
		allowedHeaders.add("*.qolome.com");
		corsConfiguration.setAllowedHeaders(allowedHeaders);
		//相同配置有效期 单位秒
		corsConfiguration.setMaxAge(300l);
		//生效作用域
		basedCorsConfigurationSource.registerCorsConfiguration("/**", corsConfiguration);
		return new CorsFilter(basedCorsConfigurationSource);
	}
}
